
//数字、字符串布尔值ts基本语法

var username:string="123"
username.substring(0,1)
var age:number=100
age.toFixed(1)
var flag:boolean=true
console.log(flag)

//可以赋值为字符串或者数字
var my:string|number='lz'

//any泛型任何都可以
var anywhat:any=123
console.log(my,anywhat);

//-----------------------------------------------------
//数组
//list:string[]里面的元素必须全是字符串
var list:string[]=['a','b','c']

var list1:number[]=[1,2,3]

var list2:(number|string)[]=[1,2,'q',12]

//另一种写法
var list3:Array<string>=['a','b','c']

var list4:Array<string|number>=[1,2,'q',12]

console.log(list,list1,list2,list3,list4);

//-----------------------------------------------------
//对象,interface制订规则
interface IObj{
  name:string,
  age:number,
  location?:string,
  //规定参数和返回值都是字符串类型
  getName:(name:string)=>string
  // ？表示可选属性
  [propName:string]:any
}

var obj:IObj={
  name:'lz',
  age:25,
  getName:(name)=>{
    return name
  }
}

console.log(obj);

//-----------------------------------------------------
//函数
function test(a:string,b:string,c?:number){
  console.log(a.substring(0,1)+b.substring(0,1));
  
}
test('aaa','bbb',123)

export default obj
